/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.openbrew.openbrewrf;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author chapmand
 */
@Entity
@Table(name = "posTasterTray")
@XmlRootElement
public class POSTasterTray implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "trayID")
    private Integer id;
    @Basic(optional = false)
    @NotNull
    @Column(name = "trayPrice")
    private float trayPrice;
    @OneToMany(cascade=CascadeType.REFRESH, fetch=FetchType.EAGER)
    @JoinTable(
        name="posJTTrayToPST",
        joinColumns={ @JoinColumn(name="trayID", referencedColumnName="trayID")},
        inverseJoinColumns={ @JoinColumn(name="servingTypeID", referencedColumnName="servingTypeID", unique=true)}
    )
    private List<POSProductServingType> servingTypeCollection;
    @OneToOne(mappedBy="tasterTray")
    private POSLineItems posLineItem;

    public POSTasterTray() {
    }

    public POSTasterTray(Integer id) {
        this.id = id;
    }

    public POSTasterTray(Integer id, float trayPrice) {
        this.id = id;
        this.trayPrice = trayPrice;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public float getTrayPrice() {
        return trayPrice;
    }

    public void setTrayPrice(float trayPrice) {
        this.trayPrice = trayPrice;
    }

    public List<POSProductServingType> getServingTypeCollection() {
        return servingTypeCollection;
    }

    public void setServingTypeCollection(List<POSProductServingType> servingTypeCollection) {
        this.servingTypeCollection = servingTypeCollection;
    }

    @XmlTransient
    public POSLineItems getPosLineItem() {
        return posLineItem;
    }

    public void setPosLineItem(POSLineItems posLineItem) {
        this.posLineItem = posLineItem;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof POSTasterTray)) {
            return false;
        }
        POSTasterTray other = (POSTasterTray) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.openbrew.openbrewrf.postastertray[ id=" + id + " ]";
    }
}
